#!/bin/bash


function do_test() {
    for i in ${1}/*; do
        if [ -x ${i} ]; then
            ${i} > /dev/null 2>&1
            res=$?
            filename=`basename $i`
            case ${res} in
                0)
                    echo -e "\033[32mtest ${filename} ${2} ${3} ${4} success\033[0m";;
                *)
                    echo -e "\033[31mtest ${filename} ${2} ${3} ${4} failed, return ${res} \033[0m";;
            esac
        fi
    done

}


function exec_cmd() {
    ${1} ${2} ${3} ${4} > /dev/null 2>&1
    res=$?
    basename=`basename $1`
    case ${res} in
        0)
            echo -e "\033[32mtest ${basename} ${2} ${3} ${4} success\033[0m";;
        *)
            echo -e "\033[31mtest ${basename} ${2} ${3} ${4} failed, return ${res} \033[0m";;
    esac
}


BASE_DIR=`pwd`

export LSAN_OPTIONS="suppressions=${BASE_DIR}/asan_check/suppressions.txt"
echo $LSAN_OPTIONS

do_test ${BASE_DIR}/output/bin/test/comm
do_test ${BASE_DIR}/output/bin/test/event
exec_cmd ${BASE_DIR}/output/bin/test/event/znx_worker_test_1 et
exec_cmd ${BASE_DIR}/output/bin/test/event/znx_worker_test_2 et
do_test ${BASE_DIR}/output/bin/test/conf
do_test ${BASE_DIR}/output/bin/test/http
